<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'codelist';
$return=array();
$plugin_name =$this->pluginname;
$filename=$_SESSION['role_id']==2?'storeid':'workerid';
$filevalue=$_SESSION['role_id']==2?$this->store_id:$this->worker_id;
if($_RQ['op']=='codelist'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array($filename=>$filevalue,'pluginname'=>$plugin_name,'uniacid'=>$_SESSION['uniacid'],'mid >'=>0);
	if(!empty($_RQ['batchid'])){
		$params['batchid']=trim($_RQ['batchid']);
		$return['params']['batchid']=trim($_RQ['batchid']);
	}
	if(!empty($_RQ['type'])){
		$params['type']=trim($_RQ['type']);
		$return['params']['type']=$_RQ['type'];
	}
	if(!empty($_RQ['listid'])){
		$params['listid']=trim($_RQ['listid']);
		$return['params']['listid']=$_RQ['listid'];
	}
	if(!empty($_RQ['storeid'])){
		$params['storeid']=trim($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if(!empty($_RQ['workerid'])){
		$params['workerid']=trim($_RQ['workerid']);
		$return['params']['workerid']=$_RQ['workerid'];
	}
	if(!empty($_RQ['status'])){
		$params['status']=trim($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if(!empty($_RQ['sn'])){
		$params['sn']='%'.trim($_RQ['sn']).'%';
		$return['params']['sn']=$_RQ['sn'];
	}
    $fields='';
    $orderby='id desc';
	$total='';
	$list=pdo_getslice('jy_kabao_batch_code',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($list as &$item){
		$item['member']=cfc('core')->member_show($item['mid']);
		$item['qumember']=cfc('core')->member_show($item['qumid']);
		$item['listtitle']=pdo_getcolumn('jy_kabao_list',array('id'=>$item['listid']),'title');
		$item['url']=custom_url('jy_kabao/item//code='.$item['sn'],true);
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['codestatus']=$this->codestatus;		
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'codelist','title'=>'领卡列表'),
		),
		'list'=>array('data'=>'list','edit'=>false,'del_op'=>'codedel','del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'领卡人','type'=>'member'),
			array('name'=>'qumember','title'=>'渠道商','type'=>'member'),
			array('name'=>'qufee','title'=>'渠道佣金','type'=>'string'),
			array('name'=>'listtitle','title'=>'所属卡包','type'=>'string'),
			array('name'=>'sn','title'=>'编号','type'=>'string'),
			array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'batchtypes'),
			array('type'=>'select','name'=>'storeid','title'=>'绑定医馆','options'=>'stores'),
			array('type'=>'select','name'=>'workerid','title'=>'绑定大夫','options'=>'workers','option_title'=>'name'),
			array('name'=>'url','title'=>'二维码','type'=>'ewm'),
			array('name'=>'url','title'=>'链接','type'=>'copy'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'codestatus'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),
		),
		'search'=>array(
			array('name'=>'type','width'=>15,'title'=>'类型','type'=>'radio','options'=>'batchtypes'),
			array('type'=>'select','width'=>15,'name'=>'listid','title'=>'所属卡包','options'=>'kabaos'),
			array('type'=>'select','width'=>15,'name'=>'storeid','title'=>'绑定医馆','options'=>'stores'),
			array('type'=>'select','width'=>15,'name'=>'workerid','title'=>'绑定大夫','options'=>'workers','option_title'=>'name'),
			array('name'=>'sn','width'=>15,'title'=>'编号','type'=>'string'),
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'radio','options'=>'codestatus'),
		)
	);
	$return['batchtypes']=$this->batchtypes;
	$return['kabaos']=pdo_getall('jy_kabao_list',array('pluginname'=>$plugin_name,'uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
	$return['stores']=pdo_getall('jy_yiliao_store',array('uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
	$return['workers']=pdo_getall('jy_yiliao_worker',array('uniacid'=>$_SESSION['uniacid']),array('name','id'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='codedel'){
	exi('不能删除！','error');
	
}
?>